package me.tuyou.activiti.taskService;

import me.tuyou.activiti.Base;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class VariableTest extends Base {

    @Test
    public void deploy() {
        repositoryService.createDeployment().addClasspathResource("VariableTest.bpmn").deploy();
    }

    /**
     * 开启一个流程
     */
    @Test
    public void startInstance() {
        Map<String, Object> variables = new HashMap<>();
        variables.put("assignee", "tuyou");
        runtimeService.startProcessInstanceByKey("VariableTest", variables);
    }

    @Test
    public void getVariables() {
        Task task = taskService.createTaskQuery().taskAssignee("tuyou").singleResult();
        System.out.println(task.getName());

        Map<String, Object> processVariables = taskService.getVariables(task.getId());
        for (String key : processVariables.keySet()) {
            System.out.println(key + ":" + processVariables.get(key));
        }

        taskService.complete(task.getId());
        checkProcessStop(task.getProcessInstanceId());

        printProcessProgress(task.getProcessInstanceId());
    }
}
